package grape.wx.rest.mp.basic.mvc;

import grape.common.rest.mvc.SuperController;
import grape.wx.service.mp.MpProperties;
import grape.wx.rest.mp.basic.mapper.MpConfigWebMapper;
import grape.wx.rest.mp.basic.vo.MpConfigVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by yangwei
 * Created at 2020/7/20 20:48
 */
@RestController
@RequestMapping("/wx/mp/config")
@Api(tags = "公众号jsapi相关接口")
public class MpConfigController extends SuperController {

    @Autowired
    private WxMpService wxMpService;
    @Autowired
    private MpProperties mpProperties;
    @Autowired
    private MpConfigWebMapper mpConfigWebMapper;

    /**
     * 公众号配置列表，主要用来下拉选择或列表查看
     * @return
     */
    @ApiOperation("公众号配置列表")
    @ResponseStatus(HttpStatus.OK)
    @GetMapping("/list")
    public List<MpConfigVo> configList() {
        return mpProperties.getConfigs().stream().map(mpConfigWebMapper::configToVo).collect(Collectors.toList());
    }
}
